-
Notifications
You must be signed in to change notification settings - Fork 108
fix: support CSP configuration as sets #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
crgwbr
commented
Dec 20, 2024
- Fixes several exceptions that'd be thrown when trying to use Python sets as config values, rather than tuples or lists.
- Removes duplicate values from directives when building the full CSP header.
In case the CI test results are private, the error for Python 3.13 is:
|
After some thought, I'm slightly negative on this PR. Looking at the Django settings reference, I can't find any settings that use a |
To me, it seems unpythonic to force the value to be a list or tuple, when really all we need is any |
Thanks for continuing to engage on this PR. Yes, I think I'm proposing In Mozilla's bedrock, a In Mozilla's fx-private-relay (where I'm a maintainer), a lot of code is used to append new items to lists and avoid duplicates: Using a if v is not None:
v = copy.copy(v)
if isinstance(v, set):
v = sorted(v)
if not isinstance(v, (list, tuple)):
v = (v,)
csp[k] = v This would be needed on both the config and update passes. This way, we've got all ordered sequences when we get down to the end of |
b55d28f
to
7a50495
Compare
Ok, I've incorporated some of those notes, but kept the duduplication logic at the end. That prevents duplicate values from creeping in if the same value is supplied twice, once by normal settings and once by an update decorator. |
Are you able to see details of failing tests? If not, I can copy them. |
Fixes several exceptions that'd be thrown when trying to use Python sets as config values, rather than tuples or lists.
I can see them, but seems like an erroneous failure. The error is due to ruff formatting:
But, I didn't change that file. When I try to reformat it by running using the version of ruff I already had installed, there was no change to the file. I had to update ruff from 0.8 -> 0.9 before it would change anything. IOW, it's only failing due to the ruff version not being pinned. Regardless, I'll push a fix in a couple minutes. |
7a50495
to
6ff5146
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @crgwbr. I think this is ready to merge, but I would prefer preserving order for the generated lists. I know devs like you using set
don't care about the order, but others using list
and tuple
expect the header to be in declaration order. If you want to make the suggested change, as well as the test updates, I'd appreciate it, but I could also make that change in my own PR. Let me know which way you'd like to go.
6ff5146
to
55e3ea0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks great. Thanks @crgwbr for sticking with the review process and being so responsive!